package com.fr.web.platform.module;

import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.XMLable;
import com.fr.base.file.ConfigManager;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.web.core.WebUtils;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

public class Module
  implements XMLable
{
  public static final String XML_TAG = "Module";
  private String name;
  private String src;
  private String position;

  public Module()
  {
    this("No Title", "");
  }

  public Module(String paramString1, String paramString2)
  {
    this(paramString1, paramString2, "");
  }

  public Module(String paramString1, String paramString2, String paramString3)
  {
    this.name = paramString1;
    this.src = paramString2;
    this.position = paramString3;
  }

  public String getModuleName()
  {
    return this.name;
  }

  public void setModuleName(String paramString)
  {
    this.name = paramString;
  }

  public String getSrc()
  {
    return this.src;
  }

  public void setSrc(String paramString)
  {
    this.src = paramString;
  }

  public String getPosition()
  {
    return this.position;
  }

  public void setPosition(String paramString)
  {
    this.position = paramString;
  }

  public String toModule()
  {
    return "<li><a href='" + this.src + "'>" + this.name + "</a></li>";
  }

  public Map map4Tpl(HttpServletRequest paramHttpServletRequest)
  {
    Map localMap = WebUtils.createTemplateMap(paramHttpServletRequest);
    localMap.put("src", this.src);
    localMap.put("moduleName", this.name);
    return localMap;
  }

  public static String toModules(Module[] paramArrayOfModule)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramArrayOfModule.length; ++i)
    {
      if (StringUtils.isNotEmpty(paramArrayOfModule[i].getPosition()))
      {
        localStringBuffer.append("<li style='float:");
        localStringBuffer.append(paramArrayOfModule[i].getPosition());
        localStringBuffer.append("'>");
      }
      else
      {
        localStringBuffer.append("<li>");
      }
      localStringBuffer.append("<a href='");
      localStringBuffer.append(FRContext.getConfigManager().getServletMapping());
      localStringBuffer.append("?op=");
      localStringBuffer.append("fr_module");
      localStringBuffer.append("'>");
      localStringBuffer.append(paramArrayOfModule[i].getModuleName());
      localStringBuffer.append("</a></li>");
    }
    return localStringBuffer.toString();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("Module"))
      {
        setSrc(paramXMLableReader.getAttr("src"));
        setModuleName(paramXMLableReader.getAttr("name"));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (!(StringUtils.isEmpty(this.src)))
      paramXMLPrintWriter.startTAG("Module").attr("name", this.name).attr("src", this.src).end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Module localModule = (Module)super.clone();
    return localModule;
  }
}